<%--
  Created by IntelliJ IDEA.
  User: 862982795
  Date: 2021/06/23
  Time: 11:05
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
    <title>停车场车位租赁管理系统</title>
</head>
<body>
<script src="js/jquery-1.12.4.js"></script>
<form method="get" action="ListServlet">
    <table>
        <caption style="font-size: 30px">停车场车位租赁管理系统</caption>
        <tr>
            <th>
                <button type="button" onclick="location.href='add..jsp'">车位租赁</button>
            </th>
            <th>
                总页码:${requestScope.page.totalPageCount}
            </th>
            <th>
                当前页码:${requestScope.page.currPageNo}
            </th>
            <th>
                单页显示的记录数:
            </th>
            <th>
                <input type="number" value="${requestScope.page.pageSize}" name="pageSize" class="pageSize">
            </th>

        </tr>
        <tr style="background-color: yellow">
            <th>租赁人姓名</th>
            <th>车牌号</th>
            <th>租赁状态</th>
            <th>到期日期</th>
            <th>操作</th>
        </tr>

        <c:forEach var="rent" items="${requestScope.page.rentList}" varStatus="status">
            <tr id="${rent.id}" <c:if test="${status.index % 2== 1 }">style="background-color:rgb(219,241,212);"</c:if>>
                <td>${rent.userName}</td>
                <td>${rent.carNum}</td>
                <td class="${rent.id}">${rent.status==0 ? '租赁中' : '已到期'}</td>
                <td>${rent.maturityDate}</td>
                <td><a href="InfoServlet?id=${rent.id}&operating=查看">查看</a>&nbsp;&nbsp;<a
                        href="InfoServlet?id=${rent.id}&operating=修改">修改</a>&nbsp;&nbsp;<a
                        href="JavaScript:void(0);" onclick="del(${rent.id});">删除</a>&nbsp;&nbsp;
                    <a href="JavaScript:void(0);" onclick="tuizu(${rent.id});"
                       class="${rent.id}">${rent.status==0 ? '退租' : '已到期'}</a>
                </td>
            </tr>
        </c:forEach>
        <tr>
            <td>租赁人姓名:</td>
            <td>
                <input type="text" value="${requestScope.page.userName}" class="userName" name="userName">
            </td>
            <td>车牌号:</td>
            <td>
                <input type="text" value="${requestScope.page.carNum}" class="carNum" name="carNum">
            </td>
            <th>
                <button>搜索</button>
            </th>
        </tr>
        <tr>
            <th><a href="JavaScript:void (0);" onclick="paging(1);">首页</a></th>
            <th><a href="JavaScript:void (0);" onclick="paging(${requestScope.page.currPageNo-1});">上一页</a></th>
            <th><a href="JavaScript:void (0);" onclick="paging(${requestScope.page.currPageNo+1});">下一页</a></th>
            <th><a href="JavaScript:void (0);" onclick="paging(${requestScope.page.totalPageCount});">尾页</a></th>
        </tr>
        <tr>
            <th colspan="5"><span class="s1"></span></th>
        </tr>
    </table>
</form>

<script>
    $("form").submit(function () {
        var pageSize = $(".pageSize").val();
        if (pageSize <= 0) {
            alert("不能小于或等于0");
            return false;
        }
    });

    paging = function (pageNo) {
        var userName = $(".userName").val();
        var carNum = $(".carNum").val();
        var pageSize = $(".pageSize").val();
        if (pageSize <= 0) {
            alert("不能小于0");
            return;
        }
        if (pageNo + 1 === 1) {
            alert("当前已是首页!");
            return;
        } else if (pageNo - 1 ===${requestScope.page.totalPageCount}) {
            alert("当前已是尾页!");
            return;
        }
        location.href = "ListServlet?userName=" + userName + "&carNum=" + carNum + "&currPageNo=" + pageNo + "&pageSize=" + pageSize;
    }

    del = function (id) {
        if (confirm("确定要删除吗?")) {
            $.get("DeleteServlet", "id=" + id, function (data) {
                if (data > 0) {
                    alert("删除成功!");
                    $("#" + id).remove();
                } else {
                    alert("删除失败!");
                }
            });
        }
    }

    tuizu = function (id) {

        if (confirm("确定要退租吗?")) {
            $.get("UpdateStatusServlet", "id=" + id, function (data) {
                if (data > 0) {
                    $(".s1").text("退租成功");
                    $("." + id).text("已到期");
                } else {

                }
            });
        }
    }


</script>

</body>
</html>
